package com.hly.utils.Main;

import com.hly.utils.Common.Config;
import com.hly.utils.Common.Context;

import java.util.Random;

public class JPushCore {

    public static IStatusListener iStatusListener;
    public static IMessageListener iMessageListener;

    public static boolean isInit = false;

    public static void register(Context context, ICore core, IStatusListener statusListener, IMessageListener messageListener) {
        iStatusListener = statusListener;
        iMessageListener = messageListener;

        while (true) {
            try {
                Thread.sleep(new Random(2000).nextInt(5000));
                if (Config.authStatus) {
                    if (!isInit) {
                        isInit = true;
                        System.out.println("授权开启了，现在进行模块初始化");
                        core.init(context);
                        System.out.println("进入监听状态...");
                        iStatusListener.onNotifyStatus(1, true, null);
                        iStatusListener.onConnectStatus(1, true, null);
                    } else {
                        if (new Random().nextBoolean()) {
                            iMessageListener.onClickNotify(null);
                        } else {
                            iMessageListener.onMessageEvent(null);
                        }
                    }
                } else {
                    System.out.println("没有开启授权");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
